package tmproject.hlhj.fhp.cartrans.activitys

import android.content.Intent
import android.support.v7.app.AlertDialog
import android.view.View
import com.tencent.bugly.beta.Beta
import kotlinx.android.synthetic.main.aty_setting.*
import tmproject.hlhj.fhp.cartrans.BaseAty
import tmproject.hlhj.fhp.cartrans.IView.SettingView
import tmproject.hlhj.fhp.cartrans.R
import tmproject.hlhj.fhp.cartrans.presenter.SettingPresenter
import tmproject.hlhj.fhp.cartrans.utils.SpHelper
import tmproject.hlhj.fhp.cartrans.utils.VersionUtil

/**
 * Created by Never Fear   on 2018\8\29 0029.
Never More....
 */
class SettingAty:BaseAty<SettingView,SettingPresenter>(), SettingView {
    override fun initView() {
        if (Beta.getUpgradeInfo()==null){
            redPoint.visibility=View.GONE
        }else{
            if (Beta.getUpgradeInfo().versionCode>VersionUtil.getVersionCode(this)){
                redPoint.visibility=View.VISIBLE
            }else{
                redPoint.visibility=View.VISIBLE
            }
        }
    }

    override fun logicStart() {
    }

    override fun setListener() {
        btExit.setOnClickListener {
            finish()
        }
        btAboutUs.setOnClickListener {
            startActivity(Intent(this@SettingAty,AboutUsAty::class.java))
        }
        btUpdata.setOnClickListener {
            startActivity(Intent(this@SettingAty,UpdataAty::class.java))

        }
        btLoginOut.setOnClickListener {
            AlertDialog.Builder(this)
                    .setTitle("确认退出？")
                    .setPositiveButton("确定"){
                        dialogInterface, i ->
                        SpHelper.saveToken(this,"")
                        startActivity(Intent(this,LoginAty::class.java))
                        dialogInterface.dismiss()
                        finish()
                    }
                    .setNegativeButton("取消"){
                        dialogInterface, i ->
                        dialogInterface.dismiss()
                    }
                    .show()

        }
    }

    override fun bindView(): SettingView {
        return this
    }

    override fun createPresenter(): SettingPresenter {
        return SettingPresenter()
    }

    override fun getContentId(): Int {
        return R.layout.aty_setting
    }
}